package com.zhuanyongjin.server;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zhuanyongjin.dao.membersDao;
import com.zhuanyongjin.dao.new_informationDao;
import com.zhuanyongjin.dao.impl.membersDaoImpl;
import com.zhuanyongjin.dao.impl.new_informationDaoImpl;
import com.zhuanyongjin.util.DataTools;

public class new_informationServlet extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		String content=request.getParameter("content");
		//虽然上传了图片的路径，但是并未上传图片
		String img_url=request.getParameter("img_url");
	    int member_id=Integer.parseInt(request.getParameter("member_id"));
	    int category_id=Integer.parseInt(request.getParameter("cat_id"));
	    int type=Integer.parseInt(request.getParameter("type"));
		new_informationDao new_informations = new new_informationDaoImpl();
		//用户将要发表的内容写入佣金社区的表中
		boolean b1=new_informations.savenew_information(DataTools.HexStringhtoString(content),member_id,img_url,category_id,type);
		if(b1==true){
			out.println("success");
		}
		else
		{
			out.println("error");
		}
		out.flush();
		out.close();
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
